package com.miaoxie.forum.module.monitor.server.services.impl;

import com.miaoxie.forum.module.monitor.server.services.IMonitorOfBiService;

import java.io.File;
import java.net.URL;

import com.miaoxie.forum.module.monitor.shared.util.XmlIo;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by miaoxie on 2017/2/21.
 */
@Service
public class MonitorOfBiService implements IMonitorOfBiService {




    public boolean saveFile(HttpServletRequest request, MultipartFile file){
        if(!file.isEmpty()){
            try{
                ClassLoader classLoader = XmlIo.class.getClassLoader();

                URL filePath = classLoader.getResource("context/conf.xml");
                File saveDir = new File(filePath.toURI());
                if(!saveDir.getParentFile().exists()){
                    saveDir.getParentFile().mkdirs();
                }
                //文件转存
                file.transferTo(saveDir);
                return true;
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        return false;
    }



}
